package ng.map;

import java.awt.Color;
import java.awt.Graphics2D;

import ng.graphics.Animation;
import ng.lib.Vector2D;

public abstract class MapObjectDynamic extends MapObject {

	protected double angularRate; // pi per tick
	protected Vector2D speed = new Vector2D(); // pixel per tick
	protected Vector2D acceleration = new Vector2D(); // pixel per tick^2

	public MapObjectDynamic(int id, Animation a, Vector2D p) {
		super(id, a, p);

		this.speed = this.acceleration = new Vector2D();
	}

	public MapObjectDynamic(Animation a, Vector2D p) {
		super(a, p);

		this.speed = this.acceleration = new Vector2D();
	}

	public MapObjectDynamic(int id) {
		super(id);
	}

	public MapObjectDynamic() {

	}

	public void setSpeed(Vector2D s) {
		this.speed = s;
	}

	public void setAcceleration(Vector2D a) {
		this.acceleration = a;
	}

	public void setAngularRate(double a) {
		this.angularRate = a;
	}

	public Vector2D getSpeed() {
		return this.speed;
	}

	public Vector2D getAcceleration() {
		return this.acceleration;
	}

	public double getAngularRate() {
		return this.angularRate;
	}

	public void tick() {
		super.tick();

		this.speed.add(this.acceleration);
		this.position.add(this.speed);
		this.angle += angularRate;
		if (this.angle >= Math.PI * 2)
			this.angle -= Math.PI * 2;
	}

	public void paintComponent(Graphics2D g2) {
		super.paintComponent(g2);

		
		// Draw Speed
		g2.setColor(Color.BLACK);

		g2.drawLine(Math.round(this.position.x
				+ this.animation.getDimension().width / 2), Math
				.round(this.position.y + this.animation.getDimension().height
						/ 2), Math.round(this.position.x
				+ this.animation.getDimension().width / 2 + this.speed.x * 20),
				Math.round(this.position.y
						+ this.animation.getDimension().height / 2
						+ this.speed.y * 20));

		// Draw Acceleration
		g2.setColor(Color.RED);
		g2.drawLine(Math.round(this.position.x
				+ this.animation.getDimension().width / 2), Math
				.round(this.position.y + this.animation.getDimension().height
						/ 2), Math.round(this.position.x
				+ this.animation.getDimension().width / 2 + this.acceleration.x * 20),
				Math.round(this.position.y
						+ this.animation.getDimension().height / 2
						+ this.acceleration.y * 20));

	}
}
